﻿using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace FirstPersonCamera
{
    public class GameTexture
    {
        float indexX;
        float indexY;
        int containerWidth;
        int containerHeight;
        string state = "whole";

        public GameTexture(float ix, float iy, int cw, int ch)
        {
            indexX = ix;
            indexY = iy;
            containerWidth = cw;
            containerHeight = ch;
        }

        public Vector2 UpperLeft()
        {
            if (state == "whole" || state == "upperHalf" || state == "leftHalf")
                return new Vector2(indexX / containerWidth, indexY / containerHeight);
            else if (state == "rightHalf")
                return new Vector2((indexX + .5f) / containerWidth, indexY / containerHeight);
            else if (state == "lowerHalf")
                return new Vector2(indexX / containerWidth, (indexY + .5f) / containerHeight);
            else if (state == "quarter")
                return new Vector2((indexX) / containerWidth, (indexY) / containerHeight);
            else
                return Vector2.Zero;
        }
        public Vector2 UpperRight()
        {
            if (state == "whole" || state == "upperHalf" || state == "rightHalf")
                return new Vector2((indexX + 1) / containerWidth, indexY / containerHeight);
            else if (state == "lowerHalf")
                return new Vector2((indexX + 1) / containerWidth, (indexY+.5f) / containerHeight);
            else if (state == "leftHalf")
                return new Vector2((indexX + 1 - .5f) / containerWidth, indexY / containerHeight);
            else if (state == "quarter")
                return new Vector2((indexX + 1 - .5f) / containerWidth, (indexY) / containerHeight);
            else
                return Vector2.Zero;
        }
        public Vector2 LowerLeft()
        {
            if (state == "whole" || state == "lowerHalf" || state == "leftHalf")
                return new Vector2(indexX / containerWidth, (indexY + 1) / containerHeight);
            else if (state == "upperHalf")
                return new Vector2(indexX / containerWidth, (indexY + 1 - .5f) / containerHeight);
            else if (state == "rightHalf")
                return new Vector2((indexX+.5f) / containerWidth, (indexY + 1) / containerHeight);
            else if (state == "quarter")
                return new Vector2((indexX) / containerWidth, (indexY + 1 - .5f) / containerHeight);
            else
                return Vector2.Zero;
        }
        public Vector2 LowerRight()
        {
            if (state == "whole" || state == "lowerHalf" || state == "rightHalf")
                return new Vector2((indexX + 1) / containerWidth, (indexY + 1) / containerHeight);
            else if (state == "upperHalf")
                return new Vector2((indexX + 1) / containerWidth, (indexY + 1 - .5f) / containerHeight);
            else if (state == "leftHalf")
                return new Vector2((indexX + 1 - .5f) / containerWidth, (indexY + 1) / containerHeight);
            else if (state == "quarter")
                return new Vector2((indexX + 1 - .5f) / containerWidth, (indexY + 1 - .5f) / containerHeight);
            else
                return Vector2.Zero;
        }

        public void setState(string texState)
        {
            state = texState;
        }
    }

}
